package com.jumi.microservice.rocketmq;

import com.alibaba.fastjson.JSONObject;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.bean.ProducerBean;
import com.aliyun.openservices.ons.api.order.ConsumeOrderContext;
import com.aliyun.openservices.ons.api.order.MessageOrderListener;
import com.aliyun.openservices.ons.api.order.OrderAction;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.jumi.microservice.common.constant.DelFlag;
import com.jumi.microservice.common.exception.BaseException;
import com.jumi.microservice.common.utils.DateUtil;
import com.jumi.microservice.common.utils.EnumUtil;
import com.jumi.microservice.constant.PayChannelEnum;
import com.jumi.microservice.constant.compensation.AfterSaleEnum;
import com.jumi.microservice.constant.compensation.AfterSaleStatusEnum;
import com.jumi.microservice.constant.compensation.AliPayStatusEnum;
import com.jumi.microservice.constant.compensation.CheckStatusEnum;
import com.jumi.microservice.constant.refundgoods.CancelUserFlagEnum;
import com.jumi.microservice.constant.refundgoods.RefundGoodsStatusEnum;
import com.jumi.microservice.constant.refundgoods.RefundTypeEnum;
import com.jumi.microservice.domain.MessageTemplate;
import com.jumi.microservice.dto.PaymentResponse;
import com.jumi.microservice.dto.order.OrderLogRequest;
import com.jumi.microservice.dto.RefundRequest;
import com.jumi.microservice.dto.compensation.transfer.PayTransferRequest;
import com.jumi.microservice.dto.refundgoods.RefundGoodsGiveUpRequest;
import com.jumi.microservice.dto.refundgoods.RefundGoodsRequest;
import com.jumi.microservice.dto.serviceDto.UpdateAfterSealStatusRequest;
import com.jumi.microservice.dto.serviceDto.UpdateReturnInfoRequest;
import com.jumi.microservice.dto.wallet.api.WalletInOrOutRequest;
import com.jumi.microservice.entity.Compensation;
import com.jumi.microservice.entity.RefundGoods;
import com.jumi.microservice.enumerate.OrderStatusEnum;
import com.jumi.microservice.enumerate.WalletTypeEnum;
import com.jumi.microservice.exception.RefundGoodsExceptionEnum;
import com.jumi.microservice.mapper.CompensationMapper;
import com.jumi.microservice.mapper.RefundGoodsMapper;
import com.jumi.microservice.rocketmq.domain.CompensationEvent;
import com.jumi.microservice.rocketmq.domain.OrderAfterSaleEvent;
import com.jumi.microservice.rocketmq.domain.RefundPartEvent;
import com.jumi.microservice.service.*;
import com.jumi.microservice.transfer.AliPayTransfer;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

/**
 * @author Scw
 * @date 2020-08-22 11:37
 */
@Service
public class CompensationRocketMqListener implements MessageOrderListener {
    private static final Logger log = LoggerFactory.getLogger(CompensationRocketMqListener.class);
    @Resource
    private CompensationMapper compensationMapper;
    @DubboReference
    private IWalletInOrOutService walletInOrOutService;
    @Resource
    private AliPayTransfer aliPayTransfer;
    @DubboReference
    private IOrderDubboService iOrderDubboService;
    @DubboReference
    private IOrderService iOrderService;
    @DubboReference
    private IPayService iPayService;
    @Resource
    private RefundGoodsMapper refundGoodsMapper;
    @DubboReference
    private IOrderGoodsService iOrderGoodsService;
    @Resource
    private RedisTemplate<String, String> redisTemplate;
    @Resource
    private ProducerBean producerBean;
    @Resource
    SendMessageHandler sendMessageHandler;

    private static final String key = "isCompensation::";

    @Override
    public OrderAction consume(Message message, ConsumeOrderContext consumeOrderContext) {
        CompensationEvent compensationEvent;
        try {
            String messageStr = new String(message.getBody());
            compensationEvent = JSONObject.parseObject(messageStr, CompensationEvent.class);
            log.info("审核同意补偿--收到message：[{}]", messageStr);
        } catch (Exception e) {
            log.error("审核同意补偿--JSON解析出错：[{}]", e.getMessage());
            return OrderAction.Success;
        }
        log.info("审核同意补偿--CompensationId：[{}]", compensationEvent.getCompensationId());
        Boolean res = redisTemplate.opsForValue().setIfAbsent(key + compensationEvent.getCompensationId(), "审核同意补偿", 7, TimeUnit.DAYS);
        if (res!=null && !res) {
            log.info("审核同意补偿重复，CompensationId：[{}]", compensationEvent.getCompensationId());
            return OrderAction.Success;
        }
        agreeCompensation(compensationEvent);
        return OrderAction.Success;
    }

    /**
     * 审核同意
     */
    private void agreeCompensation(CompensationEvent compensationEvent) {
        boolean payRes = false;
        int compensationId = compensationEvent.getCompensationId();
        Long operatorId = compensationEvent.getLoginId();
        String operatorName = compensationEvent.getLoginName();

        //查询信息
        QueryWrapper<Compensation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", compensationId);
        queryWrapper.eq("check_status", CheckStatusEnum.CHECK_STATUS_WAIT.getCode());
        Compensation compensation = compensationMapper.selectOne(queryWrapper);
        if (compensation != null) {
            compensation.setCheckStatus(CheckStatusEnum.CHECK_STATUS_AGREE.getCode().byteValue());
            compensation.setCheckOperatorId(operatorId);
            compensation.setCheckOperatorName(operatorName);
            compensation.setCheckTime(new Date());
            if (compensationMapper.updateById(compensation) > 0) {
                /*
                 * 售后类型: 1-补偿款 2-补偿邮费
                 * 1-返回钱包
                 * 2-企业支付宝打款到个人账户
                 */
                //Integer[] afterSaleTypeArr = {1, 2};
                Integer[] afterSaleTypeArr = {
                        AfterSaleEnum.AFTER_SALE_BCK.getCode(),
                        AfterSaleEnum.AFTER_SALE_BCYF.getCode()
                };
                if (Arrays.asList(afterSaleTypeArr).contains(compensation.getAfterSaleType().intValue())) {
                    //if (compensation.getAfterSaleType() > 0) {
                    //企业支付宝打款到个人账户
                    //if (compensation.getAfterSaleType() == 2) {
                    if (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCYF.getCode().byteValue()) {
                        /*
                         *  支付宝支付
                         * 企业支付宝打款给个人用户
                         * 单笔转账到支付宝账户
                         */
                        //单位：分
                        int aliAmount = compensation.getCompensationPrice().multiply(new BigDecimal("100")).intValue();
                        String aliAccount = compensation.getPayeeAccount();
                        String aliDesc = "补偿邮费到支付宝账户";
                        String aliRealName = compensation.getPayeeRealName();
                        String aliOrderSn = this.generateOrderSn();
                        //赋值
                        PayTransferRequest payTransferRequest = new PayTransferRequest();
                        payTransferRequest.setAccountId(aliAccount);
                        payTransferRequest.setAmount(aliAmount);
                        payTransferRequest.setDesc(aliDesc);
                        payTransferRequest.setRealName(aliRealName);
                        payTransferRequest.setOrderSn(aliOrderSn);
                        Map<String, String> returnMap = aliPayTransfer.doProcess(aliPayTransfer.createContext(payTransferRequest));
                        //网关返回码  10000--接口调用成功
                        String payCode = returnMap.get("code");
                        //网关返回码描述
                        String aliMsg = returnMap.get("msg");
                        //表单提交参数信息
                        String parameters = returnMap.get("parameters");

                        //成功返回信息
                        //商户转账唯一订单号
                        String outBizNo = "";
                        if (returnMap.containsKey("out_biz_no")) {
                            outBizNo = returnMap.get("out_biz_no");
                        }
                        //支付宝转账单据号
                        String orderId = "";
                        if (returnMap.containsKey("order_id")) {
                            orderId = returnMap.get("order_id");
                        }
                        //支付时间
                        String payDate = "";
                        if (returnMap.containsKey("pay_date")) {
                            payDate = returnMap.get("pay_date");
                        }
                        //失败返回信息
                        //业务返回码
                        String subCode = "";
                        if (returnMap.containsKey("sub_code")) {
                            subCode = returnMap.get("sub_code");
                        }
                        //业务返回码描述
                        String subMsg = "";
                        if (returnMap.containsKey("sub_msg")) {
                            subMsg = returnMap.get("sub_msg");
                        }
                        //初始化
                        int payStatus;
                        String payMsg;
                        if ("10000".equals(payCode)) {
                            payRes = true;
                            //支付成功
                            payStatus = AliPayStatusEnum.PAY_SUCCESS.getCode();
                            payMsg = "网关返回码描述: " + aliMsg + " , 商户转账唯一订单号：" + outBizNo + " , 支付宝转账单据号: " + orderId + " , 支付时间: " + payDate;
                        } else {
                            //支付失败
                            payStatus = AliPayStatusEnum.PAY_FALSE.getCode();
                            payMsg = "网关返回码描述: " + aliMsg + " , 业务返回码：" + subCode + " , 业务返回码描述: " + subMsg;
                            // 更新审核状态
                            compensation.setCheckStatus(CheckStatusEnum.CHECK_STATUS_REFUSE.getCode().byteValue());
                            compensation.setCheckRemark(payMsg);
                            compensation.setCheckTime(new Date());
                            //补偿邮费
                            int afterSealStatus = AfterSaleStatusEnum.COMPENSATION_POSTAGE_REFUSE.getCode();
                            UpdateAfterSealStatusRequest updateAfterSealStatusRequest = new UpdateAfterSealStatusRequest();
                            updateAfterSealStatusRequest.setOrderId(compensation.getOriginalOrderId());
                            updateAfterSealStatusRequest.setGoodsId(compensation.getCompensationGoodsId());
                            updateAfterSealStatusRequest.setAfterSealStatus((byte) afterSealStatus);
                            iOrderService.updateAfterSealStatus(updateAfterSealStatusRequest);
                        }
                        // 更新支付状态
                        compensation.setPayStatus((byte) payStatus);
                        compensation.setPayTime(new Date());
                        compensation.setPayCode(payCode);
                        compensation.setPayMsg(payMsg);
                        compensation.setParameters(parameters);
                        compensationMapper.updateById(compensation);
                    } else {
                        //添加收益
                        WalletInOrOutRequest walletInOrOutRequest = new WalletInOrOutRequest();
                        walletInOrOutRequest.setRemark(AfterSaleEnum.AFTER_SALE_BCK.getDesc());
                        walletInOrOutRequest.setUserId(compensation.getBuyerId());
                        walletInOrOutRequest.setType(WalletTypeEnum.AFTER_SALE_BCK_IN.getCode());
                        walletInOrOutRequest.setAmount(compensation.getCompensationPrice());
                        walletInOrOutRequest.setOrderNo(compensation.getOriginalOrderNo());
                        boolean isAdd = walletInOrOutService.walletIn(walletInOrOutRequest).getData();
                        if (isAdd) {
                            payRes = true;
                        }
                    }
                } else {
                    /*
                     * 售后类型: 0-弃货退款
                     * 根据订单ID查询支付方式【订单表】
                     * 3-余额支付，则进钱包
                     */
                    /*
                     * 订单支付类型：0-未支付 1-支付宝支付 2-微信支付 3-余额支付 4-聚合支付 5-支付宝H5支付 6-微信H5支付 7-微信小程序支付
                     * 记录第三方退款相关信息：1、2、5、6、7
                     */
                    //Integer[] payTypeArr = {1, 2, 5, 6, 7};
                    Integer[] payTypeArr = {
                            PayChannelEnum.ALI_PAY.getCode().intValue(),
                            PayChannelEnum.WX_PAY.getCode().intValue(),
                            PayChannelEnum.ALI_PAY_H5.getCode().intValue(),
                            PayChannelEnum.WX_PAY_H5.getCode().intValue(),
                            PayChannelEnum.WX_PAY_LETS.getCode().intValue()
                    };
                    //Integer[] payTypeArr = {2, 6, 7};
                    Integer[] payWxTypeArr = {
                            PayChannelEnum.WX_PAY.getCode().intValue(),
                            PayChannelEnum.WX_PAY_H5.getCode().intValue(),
                            PayChannelEnum.WX_PAY_LETS.getCode().intValue()
                    };
                    //调用聚合支付退款接口
                    PayChannelEnum payChannelEnum = EnumUtil.getByCode(compensation.getOrderPayType(), PayChannelEnum.class);
                    RefundRequest refundRequest = new RefundRequest();
                    refundRequest.setUid(compensation.getBuyerId());
                    refundRequest.setAmount(compensation.getCompensationPrice());
                    refundRequest.setDesc(AfterSaleEnum.AFTER_SALE_QHTK.getDesc());
                    refundRequest.setPayNo(compensation.getOrderPayNo());
                    refundRequest.setOrderSn(compensation.getRefundOrderNo());
                    refundRequest.setThirdPartyPaySn(compensation.getOrderThirdPartyPaySn());
                    refundRequest.setPayChannel(payChannelEnum);
                    if (Arrays.asList(payWxTypeArr).contains(compensation.getOrderPayType().intValue())) {
                        refundRequest.setPayTotalAmount(iOrderService.getPayTotalAmount(compensation.getOrderPayNo()));
                    }
                    PaymentResponse paymentResponse = iPayService.refund(refundRequest);
                    if (Arrays.asList(payTypeArr).contains(compensation.getOrderPayType().intValue())) {
                        UpdateWrapper<RefundGoods> refundGoodsUpdateWrapper = new UpdateWrapper<>();
                        refundGoodsUpdateWrapper.eq("id", compensation.getRefundId());
                        RefundGoods refundGoodsPay = new RefundGoods();
                        refundGoodsPay.setThirdRefundInfo(paymentResponse.getResultInfo());
                        refundGoodsMapper.update(refundGoodsPay, refundGoodsUpdateWrapper);
                    }
                    //支付成功
                    if (paymentResponse.getResult()) {
                        /*
                         * 售后类型: 0-弃货退款 1-补偿款 2-补偿邮费
                         * 弃货退款 【退货表更新审核相关信息】
                         * 退货状态: 0-待处理 1-待收货 2-待审核 3-已完成 4-已拒绝 5-已取消
                         */
                        RefundGoodsGiveUpRequest refundGoodsGiveUpRequest = new RefundGoodsGiveUpRequest();
                        refundGoodsGiveUpRequest.setCheckFlag(CheckStatusEnum.CHECK_STATUS_AGREE.getCode().byteValue());
                        refundGoodsGiveUpRequest.setCheckRemark(CheckStatusEnum.CHECK_STATUS_AGREE.getDesc());
                        refundGoodsGiveUpRequest.setStatus(RefundGoodsStatusEnum.STATUS_COMPLETE.getCode().byteValue());
                        refundGoodsGiveUpRequest.setCheckOperatorId(operatorId);
                        refundGoodsGiveUpRequest.setCheckOperatorName(operatorName);
                        RefundGoodsRequest refundGoodsRequest = new RefundGoodsRequest();
                        refundGoodsRequest.setRefundId(compensation.getRefundId());
                        this.refundGoodsGiveUp(refundGoodsGiveUpRequest, refundGoodsRequest);
                        payRes = true;
                    }
                }
                if (payRes) {
                    /*
                     *  售后订单信息状态
                     */
                    RefundGoods refundGoods = new RefundGoods();
                    refundGoods.setId(compensation.getRefundId());
                    refundGoods.setCheckOperatorId(operatorId);
                    refundGoods.setCheckOperatorName(operatorName);
                    refundGoods.setCheckTime(new Date());
                    refundGoods.setCheckFlag(CheckStatusEnum.CHECK_STATUS_AGREE.getCode().byteValue());
                    refundGoods.setStatus(RefundGoodsStatusEnum.STATUS_COMPLETE.getCode().byteValue());
                    refundGoodsMapper.updateById(refundGoods);
                    /*
                     * 订单商品表更新售后状态
                     * 售后状态:
                     *      0-正常 1-已退款
                     *      2-退货审核中 3-已退货退款 4-退货退款拒绝
                     *      5-补发审核中 6-已补发 7-补发拒绝
                     *      8-补偿审核中 9-已补偿 10-补偿拒绝
                     *      11-补邮审核中 12-已补邮费 13-补邮拒绝
                     *      14-换货申请中 15-换货同意  16-换货拒绝
                     *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
                     * 售后类型：0-弃货退款 1-补偿款 2-补偿邮费
                     * after_seal_status = 3 、after_seal_status = 9 、after_seal_status = 12
                     */
                    //int afterSealStatus = compensation.getAfterSaleType() == 0 ? 3 : (compensation.getAfterSaleType() == 1 ? 9 : 12);
                    int afterSealStatus = compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_QHTK.getCode().intValue() ? AfterSaleStatusEnum.REFUND_GOODS_AGREE.getCode() : (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCK.getCode().intValue() ? AfterSaleStatusEnum.COMPENSATION_AGREE.getCode() : AfterSaleStatusEnum.COMPENSATION_POSTAGE_AGREE.getCode());
                    UpdateAfterSealStatusRequest updateAfterSealStatusRequest = new UpdateAfterSealStatusRequest();
                    updateAfterSealStatusRequest.setOrderId(compensation.getOriginalOrderId());
                    updateAfterSealStatusRequest.setGoodsId(compensation.getCompensationGoodsId());
                    updateAfterSealStatusRequest.setAfterSealStatus((byte) afterSealStatus);
                    iOrderService.updateAfterSealStatus(updateAfterSealStatusRequest);

                    /*
                     * 弃货退款
                     * 先更新 订单商品售后状态，再去判断是否需要更新 订单状态
                     */
                    if (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_QHTK.getCode().intValue()) {
                        /*
                         * 根据退货ID查询退货相关信息
                         */
                        QueryWrapper<RefundGoods> queryWrapperRefundGoods = new QueryWrapper<>();
                        queryWrapperRefundGoods.eq("id", compensation.getRefundId());
                        RefundGoods refundGoodsSendMess = refundGoodsMapper.selectOne(queryWrapperRefundGoods);
                        if (refundGoodsSendMess != null) {
                            /*
                             * 给用户服务发送消息
                             */
                            OrderAfterSaleEvent orderAfterSaleEvent = new OrderAfterSaleEvent();
                            //订单ID
                            orderAfterSaleEvent.setOrderId(refundGoodsSendMess.getOriginalOrderId());
                            //订单编号
                            orderAfterSaleEvent.setOrderNo(refundGoodsSendMess.getOriginalOrderNo());
                            //skuId
                            orderAfterSaleEvent.setSkuId(refundGoodsSendMess.getRefundGoodsId());
                            //spuId
                            orderAfterSaleEvent.setSpuId(refundGoodsSendMess.getRefundSpuId());
                            //售后数量
                            orderAfterSaleEvent.setAfterNum(refundGoodsSendMess.getRefundNum());
                            //购买数量
                            orderAfterSaleEvent.setBuyNum(refundGoodsSendMess.getGoodsAmount());

                            Message message = new Message("orderAfterSale", "", "", JSONObject.toJSONBytes(orderAfterSaleEvent));
                            producerBean.send(message);

                            //给发票发消息
                            RefundPartEvent refundPartEvent = new RefundPartEvent();
                            //售后类型：0-退款 1-退货
                            refundPartEvent.setAfterType(1);
                            //是否全部订单：0-否 1-是
                            refundPartEvent.setComplete(0);
                            //订单编号
                            refundPartEvent.setOrderNo(refundGoodsSendMess.getOriginalOrderNo());
                            //商品skuId
                            refundPartEvent.setGoodsId(refundGoodsSendMess.getRefundGoodsId());
                            Message message2 = new Message("invoice", "", "", JSONObject.toJSONBytes(refundPartEvent));
                            producerBean.send(message2);

                            //推送订单退款通知消息
                            MessageTemplate messageTemplate = sendMessageHandler.getMessageTemplate(9);
                            String appMessageContent = messageTemplate == null ? "" : messageTemplate.getSmtAppContent().replace("{}", compensation.getCompensationPrice().toString());
                            String stationMessageContent = messageTemplate == null ? "" : messageTemplate.getSmtMessageContent().replace("{}", compensation.getCompensationPrice().toString());
                            sendMessageHandler.sendMessage("", appMessageContent, stationMessageContent,
                                    refundGoodsSendMess.getGoodsPic(), refundGoodsSendMess.getBuyerId(), 9);
                        }
                    }

                    /*
                     * 操作日志表插入相关信息
                     */
                    String logInfo = "售后处理-";
                    if (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCK.getCode().byteValue()) {
                        logInfo += "同意补偿款";
                    } else if (compensation.getAfterSaleType() == AfterSaleEnum.AFTER_SALE_BCYF.getCode().byteValue()) {
                        logInfo += "同意补邮费";
                    } else {
                        logInfo += "同意退货退款并弃货";
                    }
                    //用户标识，1 前端用户， 2 后端管理员
                    Byte userFlag = CancelUserFlagEnum.USER_FLAG_ADMIN.getCode().byteValue();
                    OrderLogRequest orderLogRequest = new OrderLogRequest();
                    orderLogRequest.setLog(logInfo);
                    orderLogRequest.setOperatorId(operatorId);
                    orderLogRequest.setOperatorName(operatorName);
                    orderLogRequest.setUserFlag(userFlag);
                    orderLogRequest.setOrderSn(compensation.getOriginalOrderNo());
                    iOrderDubboService.addOrderLog(orderLogRequest);
                }
            }
        }
    }

    /**
     * 生成订单号
     */
    private String generateOrderSn() {
        String time = DateUtil.getAllMSTime().substring(2);
        int randomInt = ThreadLocalRandom.current().nextInt(10, 100);
        return "BC" + time + randomInt;
    }

    /**
     * 弃货审核
     *
     * @param refundGoodsGiveUpRequest
     * @param refundGoodsRequest
     * @return
     */
    private Boolean refundGoodsGiveUp(RefundGoodsGiveUpRequest refundGoodsGiveUpRequest, RefundGoodsRequest refundGoodsRequest) {
        boolean res = false;
        int refundId = refundGoodsRequest.getRefundId();
        //查询信息
        QueryWrapper<RefundGoods> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", refundId);
        queryWrapper.eq("status", RefundGoodsStatusEnum.STATUS_CHECK.getCode());
        queryWrapper.eq("refund_type", RefundTypeEnum.REFUND_TYPE_GOODS.getCode());
        RefundGoods refundGoods = refundGoodsMapper.selectOne(queryWrapper);
        if (refundGoods == null) {
            throw new BaseException(RefundGoodsExceptionEnum.INFO_NO_EXIST.getCode(), RefundGoodsExceptionEnum.INFO_NO_EXIST.getMessage());
        }
        refundGoods.setCheckFlag(refundGoodsGiveUpRequest.getCheckFlag());
        refundGoods.setCheckRemark(refundGoodsGiveUpRequest.getCheckRemark());
        refundGoods.setCheckOperatorId(refundGoodsGiveUpRequest.getCheckOperatorId());
        refundGoods.setCheckOperatorName(refundGoodsGiveUpRequest.getCheckOperatorName());
        refundGoods.setCheckTime(new Date());
        if (refundGoodsMapper.updateById(refundGoods) > 0) {
            if (refundGoodsGiveUpRequest.getCheckFlag() == CheckStatusEnum.CHECK_STATUS_AGREE.getCode().byteValue()) {
                /*
                 * 售后状态:
                 *      0-正常 1-已退款
                 *      2-退货审核中 3-已退货退款 4-退货退款拒绝
                 *      5-补发审核中 6-已补发 7-补发拒绝
                 *      8-补偿审核中 9-已补偿 10-补偿拒绝
                 *      11-补邮审核中 12-已补邮费 13-补邮拒绝
                 *      14-换货申请中 15-换货同意  16-换货拒绝
                 *      17-补发漏发审核中 18-已补发漏发 19-补发漏发拒绝
                 * after_seal_status = 3
                 */
                UpdateReturnInfoRequest updateReturnInfoRequest = new UpdateReturnInfoRequest();
                updateReturnInfoRequest.setOrderId(refundGoods.getOriginalOrderId());
                updateReturnInfoRequest.setGoodsId(refundGoods.getRefundGoodsId());
                updateReturnInfoRequest.setReturnCount(refundGoods.getRefundNum());
                updateReturnInfoRequest.setReturnPrice(refundGoods.getRefundPrice());
                updateReturnInfoRequest.setReturnPostage(refundGoods.getRefundPostage());
                res = iOrderService.updateReturnInfo(updateReturnInfoRequest);
            }
        }
        return res;
    }
}
